﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.MefExtensions.Modularity;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Mysoft.ServerMonitoring.OMKit.Infrastructure;
using ProjTemp.Desktop.Common.Module;
using ProjTemp.Common.Logging;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.ServiceLocation;
using ProjTemp.Desktop.Common.Controller;
using ProjTemp.Common;
using ProjTemp.Desktop.Common;
using System.Windows;
using ProjTemp.Desktop.Common.ResourceManagement;
using Csla;
using Mysoft.ServerMonitoring.OMKit.Views;

namespace Mysoft.ServerMonitoring.OMKit
{
    [ModuleExport(typeof(ShellModule), InitializationMode = InitializationMode.WhenAvailable)]
    internal class ShellModule : ModuleBase
    {
        [ImportingConstructor]
        public ShellModule(ILogger logger, IRegionManager regionManager, IEventAggregator eventAggregator, IServiceLocator serviceLocator)
            : base(logger, regionManager, eventAggregator, serviceLocator)
        {
        }

        public override void Initialize()
        {
            //this.InitializeResourceManager();
            this._regionManager.RegisterViewWithRegion(RegionNames.TitleBarRegion, typeof(TitleBar));
            var applicationController = this._serviceLocator.GetInstance<IController>(MefContractNames.ApplicationControllerContractName);
            applicationController.Run();
        }

        private void InitializeResourceManager()
        {
            var resourceManager = this._serviceLocator.GetInstance<IResourceManage>();
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Error.en-US.xaml") }, DesktopConst.LanguageResourceSubject, "en-US");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Message.en-US.xaml") }, DesktopConst.LanguageResourceSubject, "en-US");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Resource.en-US.xaml") }, DesktopConst.LanguageResourceSubject, "en-US");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Validation.en-US.xaml") }, DesktopConst.LanguageResourceSubject, "en-US");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Error.zh-CN.xaml") }, DesktopConst.LanguageResourceSubject, "zh-CN");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Message.zh-CN.xaml") }, DesktopConst.LanguageResourceSubject, "zh-CN");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Resource.zh-CN.xaml") }, DesktopConst.LanguageResourceSubject, "zh-CN");
            resourceManager.AddResourceDictionary(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Mysoft.ServerMonitoring.OMKit.Resource;component/Lang/Validation.zh-CN.xaml") }, DesktopConst.LanguageResourceSubject, "zh-CN");
            resourceManager.SetDefaultAspect(DesktopConst.LanguageResourceSubject, "zh-CN");
        }
    }
}
